<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单退款列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="case-form">
                <div class="select-list">
                    <ul>
                        <li>
                            <p style="width: 110px;">关联订单号：</p>
                            <input type="text" name="refundOrderSn"/>
                        </li>
                        <li>
                            <p style="width: 110px;">退款单号：</p>
                            <input type="text" name="refundSn"/>
                        </li>
                        <li>
                            <p style="width: 110px;">退款订单类型：</p>
                            <select name="orderType" th:with="type=${@dict.getType('refund_order_type')}">
                                <option value="-1">全部</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <p style="width: 110px;">退款状态：</p>
                            <select name="refundStatus" th:with="type=${@dict.getType('refund_status')}">
                                <option value="-1">全部</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li class="select-time">
                            <p style="width: 110px">申请时间： </p>
                            <input type="text" class="time-input" placeholder="开始时间"
                                   name="createBeginTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" placeholder="结束时间"
                                   name="createEndTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">

        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    const prefix = ctx + "back/shopOrderRefund";
    const editFlag = [[${@permission.hasPermi('back:orderRefund:edit')}]];
    const refundFlag = [[${@permission.hasPermi('back:shopOrderRefund:refund')}]];
    const refundStatusDict = [[${@dict.getType('refund_status')}]];
    const refundOrderTypeDict = [[${@dict.getType('refund_order_type')}]];

    $(function () {
        var options = {
            url: prefix + "/searchList",
            modalName: "订单退款",
            sortName: "createTime",
            sortOrder: "desc",
            height: 600,
            showColumns: false,
            clickToSelect: true,
            columns: [
                {
                    field: 'id',
                    title: '退款ID',
                    visible: false
                },
                {
                    field: 'orderType',
                    title: '退款类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(refundOrderTypeDict, value);
                    }
                },
                {
                    field: 'refundSn',
                    title: '退款单号'
                },
                {
                    field: 'refundOrderSn',
                    title: '关联订单号',
                    // formatter: function (value, row, index) {
                    //     return '<a style="text-decoration:underline" href="javascript:void(0)" onclick="$.operate.detail(\'' + value + '\',1000)">' + value + '</a>';
                    // }
                },
                {
                    field:'orderPayCost',
                    title:'订单实付金额'
                },
                {
                    field:'refundAmount',
                    title:'退款金额'
                },
                {
                    field: 'refundStatus',
                    title: '退款状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(refundStatusDict, value);
                    }
                },
                {
                    field: 'createBy',
                    title: '申请人',
                    sortable: true
                },
                {
                    field: 'createTime',
                    title: '申请时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        let actions = [];
                        switch (parseInt(row.refundStatus)) {
                            case 1:
                                actions.push('<a class="btn btn-warning btn-xs ' + refundFlag + '" href="#" onclick="refund(\'' + row.refundSn + '\')">立即退款</a> ');
                                break;
                            case 2:
                                actions.push('<a class="btn btn-warning btn-xs ' + refundFlag + '" href="#" onclick="refresh(\'' + row.refundSn + '\')"><i class="fa fa-ref">刷新状态</i></a> ');

                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //刷新退款状态
    function refresh(refundSn) {
        $.modal.confirm("刷新退款单号" + refundSn + "的退款状态，请确认？", function () {
            $.modal.loading("正在刷新，请稍后...");
            $.get(prefix + "/refresh/"+refundSn, function (result) {
                if (result.code == web_status.SUCCESS) {
                    $.modal.alertSuccess(result.msg)
                    $.table.refresh();
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        });
    }

    //用户退款
    function refund(refundSn) {
        $.modal.confirm("为退款单号" + refundSn + "的订单全额退款，请确认？", function () {
            $.modal.loading("正在退款，请稍后...");
            $.get(prefix+"/refund/"+refundSn, function (result) {
                if (result.code == web_status.SUCCESS) {
                    $.table.refresh();
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        });
    }
</script>
</body>
</html>